package com.koumi.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.koumi.entity.UserInfo;

public class OnlineUserListener implements HttpSessionListener {
	 public void sessionCreated(HttpSessionEvent event) {
		 	Object obj = event.getSession().getAttribute("userSession");
		 	if(obj != null){
		        UserInfo u = (UserInfo) obj; 
		        System.out.println("你登录网站========="+u.getUserSessionId());
		        u.setUserSessionId(event.getSession().getId());  
		        event.getSession().setAttribute("currentUser",u);  
		        OnlineUsers.getInstance().addUser(u);  
		 	}
	    }  
	  
	    public void sessionDestroyed(HttpSessionEvent event) {  
	        System.out.println("删除用户:"+event.getSession().getAttribute("currentUser"));  
	        OnlineUsers.getInstance().removeUser(event.getSession().getId());  
	    }  
}
